*> 100 Cool Things - http://cobolrocks.codeplex.com/
*> Copyright (c) 2009
*> by Emerson Lopes (emersonlopes@gmail.com)
*>
*> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
*> documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
*> the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
*> to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*>
*> The above copyright notice and this permission notice shall be included in all copies or substantial portions 
*> of the Software.
*>
*> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
*> TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
*> THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
*> CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
*> DEALINGS IN THE SOFTWARE.

CLASS-ID. FujitsuConcreteFactory as "AFP.FujitsuConcreteFactory". 
    environment division.
        configuration section.
            repository.
                interface ICheckoutAbstractFactory       as "AFP.ICheckoutAbstractFactory"
                interface ICashDrawerAbstractProduct     as "AFP.ICashDrawerAbstractProduct"
                interface IReceiptPrinterAbstractProduct as "AFP.IReceiptPrinterAbstractProduct"
                
                *>Cash drawers classes
                class     ClassTeamPos1054258002         as "AFP.Drivers.CashDrawers.TeamPoS105428002"
                class     ClassTeamPos10PB60014          as "AFP.Drivers.CashDrawers.TeamPoS0PB60014"
                
                *>Receipt printers classes
                class     ClassTeamPOSFD21               as "AFP.Drivers.ReceiptPrinters.TeamPOSFD21"
                class     ClassTeamPOSFD22               as "AFP.Drivers.ReceiptPrinters.TeamPOSFD22"
                
                class     ClassUtils                     as "AFP.Utils"
                class     CollectionHashTable            as "System.Collections.Hashtable"
                class     SystemString                   as "System.String"
                class     SystemObject                   as "System.Object".

    object. implements ICheckoutAbstractFactory.               
        data division.
            working-storage section.
                01 checkoutHardware    usage object reference SystemString.
                01 receiptPrinterName  pic n(80) value spaces.
                01 cashDrawerName      pic n(80) value spaces.
                01 driver              usage object reference SystemObject.
                01 drivers             usage object reference CollectionHashTable.             
                
        procedure division.
            method-id. NEW.
                procedure division.
                    *> Getting all drivers at once
                    invoke ClassUtils "GetCheckoutDrivers" returning drivers.
                    
            end method NEW.
            
            method-id. CreateCashDrawer as "CreateCashDrawer".   
                data division.
                    linkage section.
                        01 cashDrawer usage object reference ICashDrawerAbstractProduct.
             
                procedure division returning cashDrawer.
                
                    *> Get cashDrawer and receipt drivers
                    
                    set   driver            to  drivers::"get_Item"("CashDrawer")
                    set   cashDrawerName    to  driver as SystemString
                    
                    *> creating the cash drawer class defined in the configuration file
                    evaluate cashDrawerName 
                             when n"TeamPos1054258002"
                                  invoke ClassTeamPos1054258002 "NEW" returning cashDrawer

                             when n"TeamPos10PB60014"
                                  invoke ClassTeamPos10PB60014 "NEW" returning cashDrawer
                    end-evaluate
             
            end method CreateCashDrawer.

            method-id. CreateReceiptPrinter as "CreateReceiptPrinter".   
                data division.
                    linkage section.
                        01 receiptPrinter usage object reference IReceiptPrinterAbstractProduct.
             
                procedure division returning receiptPrinter.
                    *> Get cashDrawer and receipt drivers
                    
                    set   driver              to  drivers::"get_Item"("ReceiptPrinter")
                    set   receiptPrinterName  to  driver as SystemString
                    
                    *> creating the receipt printer class defined in the configuration file
                    
                    evaluate receiptPrinterName 
                             when n"TeamPoSFD21"
                                  invoke ClassTeamPoSFD21 "NEW" returning receiptPrinter

                             when n"TeamPoSFD22"
                                  invoke ClassTeamPoSFD22 "NEW" returning receiptPrinter
                    end-evaluate
             
            end method CreateReceiptPrinter.
    end object.                
END CLASS FujitsuConcreteFactory.

      
      
